//
//  Tool.m
//  呼应
//
//  Created by apple on 15/6/24.
//  Copyright (c) 2015年 apple. All rights reserved.
//

#import "Tool.h"

@implementation Tool

//手机号校验
+ (BOOL)checkTel:(NSString *)str

{
    
    if ([str length] == 0) {
        //手机号为空
        [Tool showSmallMSG:@"手机号不能为空" shake:YES];
        return NO;
    }
    NSString *regex = @"^((13[0-9])|(14[0-9])|(17[0-9])|(15[0-9])|(18[0-9]))\\d{8}$";
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    BOOL isMatch = [pred evaluateWithObject:str];
    if (!isMatch) {
        [Tool showSmallMSG:@"请输入正确的手机号" shake:YES];
        return NO;
    }
    return YES;
}



+(BOOL)checkMobile:(NSString *)mobile{
    if (mobile.length != 11)
    {
        [self showSmallMSG:@"手机号长度只能是11位" shake:YES];
        return NO;
    }else{
        /**
         * 移动号段正则表达式
         */
        NSString *CM_NUM = @"^((13[4-9])|(147)|(15[0-2,7-9])|(178)|(18[2-4,7-8]))\\d{8}|(1705)\\d{7}$";
        /**
         * 联通号段正则表达式
         */
        NSString *CU_NUM = @"^((13[0-2])|(145)|(15[5-6])|(176)|(18[5,6]))\\d{8}|(1709)\\d{7}$";
        /**
         * 电信号段正则表达式
         */
        NSString *CT_NUM = @"^((133)|(153)|(177)|(18[0,1,9]))\\d{8}$";
        NSPredicate *pred1 = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CM_NUM];
        BOOL isMatch1 = [pred1 evaluateWithObject:mobile];
        NSPredicate *pred2 = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CU_NUM];
        BOOL isMatch2 = [pred2 evaluateWithObject:mobile];
        NSPredicate *pred3 = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CT_NUM];
        BOOL isMatch3 = [pred3 evaluateWithObject:mobile];
        
        if (isMatch1 || isMatch2 || isMatch3) {
            return YES;
        }else{

            [Tool showSmallMSG:@"请输入正确的手机号码" shake:YES];
            return NO;
        
        }
    }
    return nil;

}




//车牌号校验
+ (BOOL)checkCar:(NSString *)str

{
    
    if ([str length] == 0) {
        //车牌号为空
        UIAlertView *alertView=[[UIAlertView alloc] initWithTitle:@"车牌号不能为空" message:@"请键入车牌号号" delegate:self cancelButtonTitle:@"好" otherButtonTitles:nil];
        [alertView show];
        
        return NO;
        
    }
    
    NSString *regex = @"^[\u4e00-\u9fa5]{1}[A-Z]{1}[A-Z_0-9]{5}$";
    
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    
    BOOL isMatch = [pred evaluateWithObject:str];
    
    if (!isMatch) {
        
        UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"请输入正确的车牌号" delegate:nil cancelButtonTitle:@"好" otherButtonTitles:nil, nil];
        
        [alert show];
        return NO;
        
    }
    
    return YES;
    
}



+(BOOL)checkPerson:(NSString *)str{
    
    if (str.length!=18) {
        
        [self showSmallMSG:@"请输入正确的身份证号码" shake:YES];
        
        return NO;
        
    }

        NSMutableArray *IDArray = [NSMutableArray array];
        // 遍历身份证字符串,存入数组中
        for (int i = 0; i < 18; i++) {
            NSRange range = NSMakeRange(i, 1);
            NSString *subString = [str substringWithRange:range];
            [IDArray addObject:subString];
        }
        // 系数数组
        NSArray *coefficientArray = [NSArray arrayWithObjects:@"7", @"9", @"10", @"5", @"8", @"4", @"2", @"1", @"6", @"3", @"7", @"9", @"10", @"5", @"8", @"4", @"2", nil];
        // 余数数组
        NSArray *remainderArray = [NSArray arrayWithObjects:@"1", @"0", @"X", @"9", @"8", @"7", @"6", @"5", @"4", @"3", @"2", nil];
        // 每一位身份证号码和对应系数相乘之后相加所得的和
        int sum = 0;
        for (int i = 0; i < 17; i++) {
            int coefficient = [coefficientArray[i] intValue];
            int ID = [IDArray[i] intValue];
            sum += coefficient * ID;
        }
        // 这个和除以11的余数对应的数
        NSString *strInside = remainderArray[(sum % 11)];
        // 身份证号码最后一位
        NSString *string = [str substringFromIndex:17];
        // 如果这个数字和身份证最后一位相同,则符合国家标准,返回YES
        if ([strInside isEqualToString:string]) {
            return YES;
        } else {
            
            [self showSmallMSG:@"请输入正确的身份证号码" shake:YES];
            
            return NO;
        }
  

}



////身份证号校验
//+ (BOOL)checkPerson:(NSString *)str{
//    if ([str length] == 0) {
//        //身份证号为空
//        UIAlertView *alertView=[[UIAlertView alloc] initWithTitle:@"身份证号不能为空" message:@"请键入身份证号" delegate:self cancelButtonTitle:@"好" otherButtonTitles:nil];
//        [alertView show];
//        
//        return NO;
//        
//    }
//    
////    NSString *regex = @"^(\\d{14}|\\d{17})(\\d|[xX])$";
//    
////    NSString * regex = @"/^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9]|X)$/";
//    
////    NSString * regex = @"/^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{4}$/";
//    
////  NSString * regex =  @"/^(^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}$)|(^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])((\\d{4})|\\d{3}[Xx])$)$/";
//    
//
//    NSString * regex =@"[1-6][0-7][\\d]{4}((19[\\d]{2})|(20[0-1][\\d]))((0[1-9])|(1[0-2]))((0[1-9])|([1-2]\\d)|(3[0-1]))[\\d]{3}[\\dx]";
//    
////    NSString * regex = @"/^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{4}$/";
//    
//    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
//    
//    BOOL isMatch = [pred evaluateWithObject:str];
//    
//    if (!isMatch) {
//        
//        UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"请输入正确的身份证号" delegate:nil cancelButtonTitle:@"好" otherButtonTitles:nil, nil];
//        
//        [alert show];
//        return NO;
//        
//    }
//    
//    return YES;
//
//}

//ip地址校验
+ (BOOL)checkIpAddress:(NSString *)str{
//    if ([str length] == 0) {
//        //身份证号为空
//        UIAlertView *alertView=[[UIAlertView alloc] initWithTitle:@"提示" message:@"内容为空" delegate:self cancelButtonTitle:@"好" otherButtonTitles:nil];
//        [alertView show];
//        return NO;
//    }
    NSString *regex = @"^(http|https)://([\\w-]+\\.)+[\\w-]+(/[\\w-./?%&=]*)?$";
    
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    
    BOOL isMatch = [pred evaluateWithObject:str];
    
    if (!isMatch) {
        return NO;
    }else{
        return YES;
    }
    return YES;
}

+ (void)setNavBarBgColor:(UINavigationController *)nav{
    
    //设置title颜色
    NSDictionary *dict = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:NSForegroundColorAttributeName];
    nav.navigationBar.titleTextAttributes = dict;
    
    if ( IOS7_OR_LATER )
    {
        nav.navigationBar.tintColor = [UIColor whiteColor];
        
        if ([nav.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)]) {
            
            [nav.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbg"] forBarMetrics:UIBarMetricsDefault];
           
        }
    }
    else
    {
        [nav.navigationBar insertSubview:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"navbg"]] atIndex:1];
    }
    
}
+ (void)setNavBarBgColor1:(UINavigationController *)nav{
    
    
    //设置title颜色
    NSDictionary *dict = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:NSForegroundColorAttributeName];
    nav.navigationBar.titleTextAttributes = dict;
    
    if ( IOS7_OR_LATER )
    {
        nav.navigationBar.tintColor = [UIColor whiteColor];
        
        if ([nav.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)]) {
            
            [nav.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbg1"] forBarMetrics:UIBarMetricsDefault];
            
        }
    }
    else
    {
        [nav.navigationBar insertSubview:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"navbg1"]] atIndex:1];
    }
    
}

//设置nav的titleview
+ (void)setNavTitleView:(UIViewController*)ctrl{
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"logo3_03.png"]];
    ctrl.navigationItem.titleView = imageView;
}

//延迟执行的block
+ (void)performBlock:(void (^)(void))block afterDelay:(NSTimeInterval)delay
{
    block = [block copy];
    [self performSelector:@selector(fireBlockAfterDelay:) withObject:block afterDelay:delay];
}

+ (void)fireBlockAfterDelay:(void (^)(void))block
{
    block();
}

//添加返回按钮
+ (void)addBackButton:(UIViewController*)ctrl{
    ctrl.navigationController.interactivePopGestureRecognizer.delegate=(id)self;
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [backBtn setFrame:CGRectMake(0, 10, 20, 20)];
    [backBtn setContentMode:UIViewContentModeScaleAspectFill];
    //    [backBtn setContentEdgeInsets:UIEdgeInsetsMake(10, 10, 10, 10)];
    [backBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    [backBtn addTarget:ctrl action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    ctrl.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
}


//从nav以下开始算页面
+ (void)setEdgesForExtendedLayout:(UIViewController*)ctrl{
    if ([ctrl respondsToSelector:@selector(setEdgesForExtendedLayout:)]) {
        [ctrl setEdgesForExtendedLayout:UIRectEdgeNone];
    }
}


//设置button点击效果
+ (void)setBtnSelectedStyle:(UIButton*)sender Image:(NSString*)image{
    if (image) {
        [sender setBackgroundImage:[UIImage imageNamed:image] forState:UIControlStateSelected];
    }
    [sender setSelected:YES];
    
    [Tool performBlock:^{
        [sender setSelected:NO];
    } afterDelay:0.05];
    
}

//十六进制的颜色转换为UIColor
+ (UIColor *) colorWithHexString: (NSString *)color alpha: (float)alpha
{
    NSString *cString = [[color stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];
    
    // String should be 6 or 8 characters
    if ([cString length] < 6) {
        return [UIColor clearColor];
    }
    
    // strip 0X if it appears
    if ([cString hasPrefix:@"0X"])
        cString = [cString substringFromIndex:2];
    if ([cString hasPrefix:@"#"])
        cString = [cString substringFromIndex:1];
    if ([cString length] != 6)
        return [UIColor clearColor];
    
    // Separate into r, g, b substrings
    NSRange range;
    range.location = 0;
    range.length = 2;
    
    //r
    NSString *rString = [cString substringWithRange:range];
    
    //g
    range.location = 2;
    NSString *gString = [cString substringWithRange:range];
    
    //b
    range.location = 4;
    NSString *bString = [cString substringWithRange:range];
    
    // Scan values
    unsigned int r, g, b;
    [[NSScanner scannerWithString:rString] scanHexInt:&r];
    [[NSScanner scannerWithString:gString] scanHexInt:&g];
    [[NSScanner scannerWithString:bString] scanHexInt:&b];
    
    return [UIColor colorWithRed:((float) r / 255.0f) green:((float) g / 255.0f) blue:((float) b / 255.0f) alpha:alpha];
}



+ (UIImage *)imageFromView:(UIView *)viewBac
{
    UIGraphicsBeginImageContextWithOptions(viewBac.bounds.size, YES, viewBac.layer.contentsScale);
    [viewBac.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    return image;
}

//根据文字获取label大小
+ (CGSize)getLabelSizeWithText:(NSString*)str AndSize:(CGSize)siz AndFont:(UIFont*)font{
    CGSize size;
    
    if ([[[UIDevice currentDevice] systemVersion] intValue]>=7.0) {
        NSDictionary *attribute = @{NSFontAttributeName: font};
        size = [str boundingRectWithSize:siz options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:attribute context:nil].size;
    }
    else{
        size = [str sizeWithFont:font constrainedToSize:siz lineBreakMode:NSLineBreakByCharWrapping];
    }
    
    return size;
}


+ (NSString*)timestampToString:(NSString*)stamp Format:(NSString*)format{
    
    if (stamp.length==13) {
        stamp = [stamp substringToIndex:10];
    }
    if (![stamp isKindOfClass:[NSNumber class]]) {
        if (stamp.length==0) {
            return @"";
        }
    }
    
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    
    NSArray *weekdayAry = [NSArray arrayWithObjects:@"星期日", @"星期一", @"星期二", @"星期三", @"星期四", @"星期五", @"星期六", nil];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    [dateFormatter setShortWeekdaySymbols:weekdayAry];
    
    if (format) {
        [dateFormatter setDateFormat:format];
    }
    
    NSDate *time = [NSDate dateWithTimeIntervalSince1970:[stamp intValue]];
    
    NSString *dateStr = [dateFormatter stringFromDate:time];
    return dateStr;
}

//获取当前系统的时间戳
+(long)getTimeSp{
    long time;
    NSDate *fromdate=[NSDate date];
    time=(long)[fromdate timeIntervalSince1970];
    return time;
}

//将时间戳转换成NSDate
+(NSDate *)changeSpToTime:(NSString*)spString{
    NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:[spString intValue]];
    return confromTimesp;
}
//比较日期大小
+(int)compareOneDay:(NSDate *)oneDay withAnotherDay:(NSDate *)anotherDay{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSString *oneDayStr = [dateFormatter stringFromDate:oneDay];
    NSString *anotherDayStr = [dateFormatter stringFromDate:anotherDay];
    NSDate *dateA = [dateFormatter dateFromString:oneDayStr];
    NSDate *dateB = [dateFormatter dateFromString:anotherDayStr];
    NSComparisonResult result = [dateA compare:dateB];
    NSLog(@"date1 : %@, date2 : %@", oneDay, anotherDay);
    if (result == NSOrderedDescending) {
        //NSLog(@"Date1  is in the future");
        return 1;
    }
    else if (result == NSOrderedAscending){
        //NSLog(@"Date1 is in the past");
        return -1;
    }
    //NSLog(@"Both dates are the same");
    return 0;
}

//时间转日期
+ (NSString*)weekdayStringFromDate:(NSDate*)inputDate {
    
    NSArray *weekdays = [NSArray arrayWithObjects: [NSNull null], @"周日", @"周一", @"周二", @"周三", @"周四", @"周五", @"周六", nil];
    
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    
    NSTimeZone *timeZone = [[NSTimeZone alloc] initWithName:@"Asia/Shanghai"];
    
    [calendar setTimeZone: timeZone];
    
    NSCalendarUnit calendarUnit = NSWeekdayCalendarUnit;
    
    NSDateComponents *theComponents = [calendar components:calendarUnit fromDate:inputDate];
    
    return [weekdays objectAtIndex:theComponents.weekday];
    
}

//将NSDate按yyyy-MM-dd HH:mm:ss格式时间输出
+(NSString*)nsdateToString:(NSDate *)date{
    NSDateFormatter *dateFormat=[[NSDateFormatter alloc]init];
    [dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSString* string=[dateFormat stringFromDate:date];
    return string;
}
//判断字符串是否为空
+ (BOOL) isBlankString:(NSString *)string {
    if (string == nil || string == NULL || [string isEqual:[NSNull null]]) {
        return YES;
    }
    if ([string isEqualToString:@""]) {
        return YES;
    }
    if ([string isKindOfClass:[NSNull class]]) {
        return YES;
    }
    if ([[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length]==0) {
        return YES;
    }
    return NO;
}




+ (void)ShowpromptWithMsg:(NSString *)Msg{
    UIAlertView *errorAlert = [[UIAlertView alloc] initWithTitle:@"提示" message:Msg delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
    [errorAlert show];
    [self performSelector:@selector(removeAlertView:) withObject:errorAlert afterDelay:2];
}

+ (void)ShowpromptWithMsg1:(NSString *)Msg{
    UIAlertView *errorAlert = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:Msg delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
    [errorAlert show];
    [self performSelector:@selector(removeAlertView:) withObject:errorAlert afterDelay:0.5];
}

//数组拼接为字符串
+ (NSString *)StringConversionWithArr:(NSArray *)array{
   NSString *quetionStr = [[NSString alloc]init];
    for (int i = 0; i < array.count; i++) {
        NSString *tmpStr = array[i];
        if (tmpStr.length != 0) {
            quetionStr = [quetionStr stringByAppendingString:[NSString stringWithFormat:@",%@",array[i]]];
        }
    }
    quetionStr = [quetionStr substringFromIndex:1];
    return quetionStr;
}

//移除alertView
+(void)removeAlertView:(UIAlertView*)alertView
{
    [alertView dismissWithClickedButtonIndex:0 animated:YES];
}

//字符串时间格式转化为正常时间格式
+(NSString *)changeTimeWithString:(NSString *)timestr{
    NSString *time01 = [NSString stringWithFormat:@"%@",timestr];
    if ([time01 isEqual:[NSNull null]] || time01 == nil || [time01 isEqualToString:@"(null)"]) {
        
        
    }else{
        
        long long int time1 =  ([time01 doubleValue])/1000;
        long long int date1 = (long long int)time1;
        NSDate *date2 = [NSDate dateWithTimeIntervalSince1970:date1];
        NSTimeZone *zone = [NSTimeZone systemTimeZone];
        NSInteger interval = [zone secondsFromGMTForDate: date2];
        NSDate *localeDate = [date2  dateByAddingTimeInterval: interval];
        NSString *strtime = [NSString stringWithFormat:@"%@",localeDate];
        NSString *subtime = [strtime substringWithRange:NSMakeRange(0, 16)];
        return subtime;
    }
    return nil;
}


//+(void)showSmallMSG:(NSString *)MSG{
//    
//    UILabel * lblMSG = [[UILabel alloc] initWithFrame:CGRectMake((SCREEN_W-200)/2, SCREEN_H, 200, 30)];
//    [[UIApplication sharedApplication].keyWindow addSubview:lblMSG];
//    lblMSG.text = MSG;
//    lblMSG.textColor = [UIColor whiteColor];
//    lblMSG.font = [UIFont systemFontOfSize:13];
//    lblMSG.textAlignment = NSTextAlignmentCenter;
//    lblMSG.backgroundColor = [themeColor colorWithAlphaComponent:0.9];
//    lblMSG.layer.cornerRadius = 15;
//    lblMSG.layer.masksToBounds = YES;
//    
//    NSDictionary * attr = @{NSFontAttributeName:[UIFont systemFontOfSize:13]};
//    
//    CGFloat width = [MSG boundingRectWithSize:CGSizeMake(MAXFLOAT, 20) options:NSStringDrawingUsesLineFragmentOrigin attributes:attr context:nil].size.width;
//    
//    if (width<180) {
//        width = 200;
//    }else{
//        
//        width = width+20;
//    }
//    
//        [lblMSG mas_updateConstraints:^(MASConstraintMaker *make) {
//            
//            make.centerX.equalTo([UIApplication sharedApplication].keyWindow);
//            make.bottom.equalTo([UIApplication sharedApplication].keyWindow).offset(-80);
//            make.width.mas_equalTo(width);
//            make.height.mas_equalTo(30);
//        }];
//    
//    
//        
//        [UIView animateWithDuration:0.25 animations:^{
//            
//            [[UIApplication sharedApplication].keyWindow layoutIfNeeded];
//            
//        }];
//
//    
//    
//    
//    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//
//        [lblMSG removeFromSuperview];
//    });
//
//}



//+(void)showSmallMSG:(NSString *)MSG shake:(BOOL)shake{
//    
//    UILabel * lblMSG = [[UILabel alloc] init];
//    [[UIApplication sharedApplication].keyWindow addSubview:lblMSG];
//    lblMSG.text = MSG;
//    lblMSG.textColor = [UIColor whiteColor];
//    lblMSG.font = [UIFont systemFontOfSize:13];
//    lblMSG.textAlignment = NSTextAlignmentCenter;
//    
//    lblMSG.backgroundColor = [themeColor colorWithAlphaComponent:0.9];
//    
//    
//    NSDictionary * attr = @{NSFontAttributeName:[UIFont systemFontOfSize:13]};
//    
//    CGFloat width = [MSG boundingRectWithSize:CGSizeMake(MAXFLOAT, 20) options:NSStringDrawingUsesLineFragmentOrigin attributes:attr context:nil].size.width;
//    
//    if (width<180) {
//        width = 200;
//    }else{
//        
//        width = width+20;
//    }
//    
//    
//    [lblMSG mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerX.equalTo([UIApplication sharedApplication].keyWindow);
//        make.bottom.equalTo([UIApplication sharedApplication].keyWindow).offset(-80);
//        make.width.mas_equalTo(width);
//        make.height.mas_equalTo(30);
//    }];
//    if (shake) {
//        [lblMSG shakeWithTimes:2 shakeDirection:QHLDirectionHorizontal];
//    }
//    
//    lblMSG.layer.cornerRadius = 15;
//    lblMSG.layer.masksToBounds = YES;
//    
//    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//        
//        [lblMSG removeFromSuperview];
//    });
//    
//}




+(void)setTitle:(NSString *)title forVc:(UIViewController *)controller{

    UILabel * titleView = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 64)];
    titleView.textAlignment = NSTextAlignmentCenter;
    titleView.text = title;
    titleView.textColor = [UIColor darkGrayColor];
    titleView.font = [UIFont systemFontOfSize:17];
    
    controller.navigationItem.titleView =titleView;
    
    
}

+ (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString {
    if (jsonString == nil) {
        return nil;
    }
    
    NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
    NSError *err;
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData
                                                        options:NSJSONReadingMutableContainers
                                                          error:&err];
    if(err) {
        NSLog(@"json解析失败：%@",err);
        return nil;
    }
    return dic;
}



+ (UIViewController *)getCurrentVC
{
    UIViewController *result = nil;
    
    UIWindow * window = [[UIApplication sharedApplication] keyWindow];
    if (window.windowLevel != UIWindowLevelNormal)
    {
        NSArray *windows = [[UIApplication sharedApplication] windows];
        for(UIWindow * tmpWin in windows)
        {
            if (tmpWin.windowLevel == UIWindowLevelNormal)
            {
                window = tmpWin;
                break;
            }
        }
    }
    
    UIView *frontView = [[window subviews] objectAtIndex:0];
    id nextResponder = [frontView nextResponder];
    
    if ([nextResponder isKindOfClass:[UIViewController class]])
        result = nextResponder;
    else
        result = window.rootViewController;
    
    return result;
}

+(void)setTitleView:(NSString *)title toVc:(UIViewController *)vc{
    
    UILabel * titleView = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 10, 10)];
    titleView.textAlignment = NSTextAlignmentCenter;
    titleView.text = title;
    titleView.textColor = [UIColor darkGrayColor];
    
    titleView.font = [UIFont systemFontOfSize:17];
    vc.navigationItem.titleView =titleView;

    
}



@end
